<?php
class FormProcessor_CreateAlbum extends FormProcessor {
	protected $user = null;
	protected $album = null;
	protected $db = null;
	
	public function __construct($db, $userid) {
		$this->db = $db;
		parent::__construct($this->db);
		
		$this->user = new DatabaseObject_User($this->db);
		$this->user->load($userid);
		
		$this->album = new DatabaseObject_Album($this->db);
	}
	
	public function process(Zend_Controller_Request_Abstract $request) {
		$this->albumname = $this->sanitize($request->getPost('albumname'));
		if (strlen($this->albumname) == 0) {
			$this->addError('albumname', '请输入相册名');
		} else {
			$this->album->albumname = $this->albumname;
		}
		
		if(!$this->hasError()) {
			
			$this->album->userid = $this->user->getId();
			$this->album->username = $this->user->username;
			$this->album->friend = 0;
			$this->album->dateline = time();
			
			$this->album->save();
		}
		
		return !$this->hasError();
	}
}
?>